package com.foreknow.demo15;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapDemo {
    public static void main(String[] args) {
        //创建一个Map集合容器
        Map<String,Integer> map = new HashMap<>();
        //添加元素
        map.put("one",1);
        map.put("two",2);
        map.put("three",3);
        //获取某个元素，根据key获取value
        Integer num = map.get("two");
        System.out.println(num);
        System.out.println("-------------------------------------------------");
        //遍历Map集合
        Set<Map.Entry<String,Integer>> set = map.entrySet();
        Iterator<Map.Entry<String,Integer>> it = set.iterator();
        while (it.hasNext()) {
            Map.Entry<String,Integer> entry = it.next();
            String key = entry.getKey();
            int value = entry.getValue();
            System.out.println(key + "---" + value);
        }
    }
}
